package com.config.sharding.stock.circulation.detail.complex;

import com.config.sharding.stock.circulation.complex.StockTableShardingRule;
import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author: create by God of SJF
 * @version: v1.0
 * @description: com.config.sharding.stockcirculationdetail.complex
 * @date:2021/9/22
 */
@Component
public class StockDetailTableComplex extends StockTableShardingRule implements ComplexKeysShardingAlgorithm<String> {
    @Override
    public Collection<String> doSharding(Collection<String> collection, ComplexKeysShardingValue<String> complexKeysShardingValue) {
        List<String> list = (List<String>) super.doSharding(collection,complexKeysShardingValue);
        List statusList = (List) complexKeysShardingValue.getColumnNameAndShardingValuesMap().get("_status");
        Long status = (Long) statusList.get(0);
        String statusIndex = super.detailKey(String.valueOf(status));
        List<String> list2= new ArrayList<>();
        list2.add(list.get(0)+"_"+statusIndex);
        return list2;
    }
}
